import {
    Message
} from './message.model'
const message = new Message()
Page({
    /**
     * 页面的初始数据
     */
    data: {
        messageList: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let that = this
        // 是否授权
        wx.getSetting({
            success: (res) => {
                if (res.authSetting['scope.userInfo']) {
                    // 获取消息类别
                    that.getMessageData()
                }
            }
        })
    },

    /**
     * 获取消息
     */
    getMessageData() {
        wx.showLoading({
            title: '正在加载数据',
        })
        let that = this
        message.getMessageData().then((res) => {
            that.setData({
                messageList: res.data
            })
        }).then(() => {
            wx.stopPullDownRefresh()
            wx.hideLoading()
        })
    },

    // 跳转到详情页
    clicktype(options) {
        let id = message.getDataSet(options, 'id')
        wx.navigateTo({
            url: `/pages/message-detail/message-detail?id=${id}`
        })
    }
})